package com.example.qxfw.common.util;

import lombok.Data;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.mapping.Document;
import java.lang.annotation.Annotation;

@Data
public class MongoUtil {

    public static <T> boolean insert(MongoTemplate template, T obj){
        Class<?> aClass = obj.getClass();
        Annotation[] annotations = aClass.getAnnotations();
        for (Annotation annotation:annotations){
            if (annotation instanceof Document){
                Document document=(Document) annotation;
                template.insert(obj,document.collection());
                return true;
            }
        }
        return false;
    }

}
